<?php
// +----------------------------------------------------------------------
// | OneKeyAdmin [ Believe that you can do better ]
// +----------------------------------------------------------------------
// | Copyright (c) 2020-2023 http://onekeyadmin.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: MUKE <513038996@qq.com>
// +----------------------------------------------------------------------
namespace plugins\cms\admin\controller;

use think\facade\View;
use app\admin\BaseController;
use plugins\cms\admin\model\Downloaded as DownloadedModel;
/**
 * 已下载
 */
class Downloaded extends BaseController
{
    /**
     * 显示已下载列表
     */
    public function index()
    {
        if ($this->request->isPost()) {
            $input  = input('post.');
            $search = ['keyword', 'date'];
            $order = ! empty($input['prop']) && ! empty($input['order']) ? [$input['prop'] => $input['order']] : ['create_time' => 'desc'];
            $count  = DownloadedModel::withSearch($search, $input)->count();
            $data   = DownloadedModel::withSearch($search, $input)->with(['user'])->order($order)->page($input['page'], $input['pageSize'])->select();
            foreach ($data as $key => $val) {
                if (empty($val['user'])) {
                    $data[$key]['user'] = ['email' => '游客'];
                }
            }
            return json(['status' => 'success','message' => '获取成功', 'data' => $data, 'count' => $count]);
        } else {
            return View::fetch();
        }
    }
}